package com.example.conventor;

import com.example.constant.UserStatus;
import com.example.constant.UserStatus1;
import org.springframework.core.convert.converter.Converter;
/**
 * @author jeff
 */
public class UserStatusConverter implements Converter<String, UserStatus1> {

    @Override
    public UserStatus1 convert(String source) {
        System.out.println("正在执行UserStatus的convert方法:"+source);
        int i = Integer.parseInt(source);
        UserStatus1[] values = UserStatus1.values();
        for (UserStatus1 value : values) {
            if (i==(value.getValue())) {
                System.out.println("已匹配到数据并返回");
                return value;
            }
        }
        throw new RuntimeException("无效枚举值");
    }
}
